package com.liuyi.observertest;

import com.liuyi.observer.MyObservable;
import com.liuyi.observer.MyObserver;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {
	
	MyObservable observable;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		MyObserver observer1 = new MyObserver("tom");
		MyObserver observer2 = new MyObserver("jack");
		observable = new MyObservable();
		observable.addObserver(observer1);
		observable.addObserver(observer2);
	}
	
	public void onClick(View view){
		observable.setName("haha");
	}
	
	@Override
	protected void onDestroy() {
		observable.deleteObservers();//这里必须加，防止内存泄漏
		super.onDestroy();
	}
}
